package com.example.toy.core.index.impl;

import com.example.toy.core.dataset.BigCollection;
import com.example.toy.core.dataset.BigPairCollection;
import com.example.toy.core.index.ToyIndexDictionary;
import com.example.toy.core.record.key.ToyRecordKey;
import com.example.toy.core.table.ToyTableMeta;
import com.example.toy.core.utils.ToyPathDefine;
import lombok.SneakyThrows;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.io.hfile.HFile;

import java.util.Iterator;

/**
 * HFileIndexDictionary
 *
 * @author shenbing
 * @date 2021/12/28
 */
public class HFileIndexDictionary implements ToyIndexDictionary {

  private final ToyTableMeta toyTableMeta;

  public HFileIndexDictionary(ToyTableMeta toyTableMeta) {
    this.toyTableMeta = toyTableMeta;
  }

  @Override
  public void addIndex(BigCollection<ToyRecordKey> key, Path path) {
//    Path indexDirPath = ToyPathDefine.getIndexDirPath(toyTableMeta.getBasePath());
//    FileSystem fileSystem = indexDirPath.getFileSystem(new Configuration());
//    HFile.WriterFactory writerFactory = HFile.getWriterFactory(new Configuration(), null);
//
//    key.map()
//
//    HFile.Writer writer = writerFactory.withPath().create();
//    writer.append();
  }

  @Override
  public BigPairCollection<ToyRecordKey, Iterator<Path>> findByIndex(
      BigCollection<ToyRecordKey> key) {
    return null;
  }

  @Override
  public void removeIndex(BigCollection<ToyRecordKey> key) {}

  @Override
  public void removeIndex(BigCollection<ToyRecordKey> key, Path path) {}

  @Override
  public void compact() {

  }

  public Path hashPath(Path indexPath, ToyRecordKey key) {
    return new Path(indexPath, key.getPartitionKey());
  }
}
